package com.project.file.factory;

import com.project.file.helper.FilePropertiesHelper;
import com.project.file.tool.EmptyFile;
import com.project.file.tool.BaseFile;
import com.project.file.tool.LocalFile;
import com.project.file.tool.MinIoFile;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author mengxj
 */
@Component
public class FileFactory implements ApplicationRunner {

    public static final String LOCAL = "local";

    public static final String MIN_IO = "minIo";

    private static BaseFile fileManager;

    public static BaseFile getInstance(){
        return fileManager;
    }

    private void init(){
        String type = FilePropertiesHelper.type();
        switch (type){
            case LOCAL:
                fileManager = LocalFile.getInstance();
                break;
            case MIN_IO:
                fileManager = MinIoFile.getInstance();
                break;
            default:
                fileManager = EmptyFile.getInstance();
        }
    }

    @Override
    public void run(ApplicationArguments args) {
        this.init();
    }
}
